#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int n = nums.size();
        vector<int> dp(n + 1);
        dp[0] = 0;
        for (int i = 1; i <= n; i++)
        {
            dp[i] = max(dp[i - 1] + nums[i - 1], nums[i - 1]);
        }
        int max = dp[1];
        for (int i = 2; i <= n; i++)
        {
            if (dp[i] > max)
            {
                max = dp[i];
            }
        }
        return max;
    }
};